package com.lcb.dubbo;

import com.lcb.client.UserService;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.ProtocolConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;

import java.io.IOException;

public class DubboServer {
    public static void main(String[] args) throws IOException {
        //开始暴露UserService服务
        //application
        ApplicationConfig applicationConfig = new ApplicationConfig("sample-app");

        //协议protocol -dubbo协议
        ProtocolConfig protocolConfig = new ProtocolConfig();
        protocolConfig.setName("dubbo");
        protocolConfig.setPort(-1);//20880
        //注册中心 register 直连
        // RegistryConfig registryConfig = new RegistryConfig(RegistryConfig.NO_AVAILABLE);
        RegistryConfig registryConfig = new RegistryConfig("zookeeper://192.168.25.134:2181");
        //service
        ServiceConfig serviceConfig = new ServiceConfig();
        serviceConfig.setRegistry(registryConfig);
        serviceConfig.setInterface(UserService.class);
        serviceConfig.setRef(new UserServiceImpl());
        serviceConfig.setProtocol(protocolConfig);
        serviceConfig.setApplication(applicationConfig);

        //实际暴露方法
        serviceConfig.export();

        System.out.println("服务启动成功!");

        System.in.read();

    }
}
